<template>
  <PageContainer 
    :show-nav-bar="isMiniProgram"
    :show-back="false"
    :background-color="'transparent'"
    :nav-bar-style="{ backgroundColor: 'transparent', color: '#fff' }"
  >
    <view class="user-profile">
      <!-- 顶部个人信息区域 -->
      <view class="user-header">
        <image class="header-bg-image" :src="getImageUrl('/static/Images/user/Toubu.png')" mode="aspectFill"></image>
        <view class="header-bg"></view>
        
        <!-- 设置按钮 -->
        <view class="settings-btn" @click="navigateToSettings">
          <image class="settings-icon" :src="getImageUrl('/static/Images/user/Shezhi.png')" mode="aspectFit"></image>
        </view>
      
      <!-- 用户信息 -->
      <view class="user-info">
        <view class="avatar-container">
          <image class="avatar" :src="userInfo.avatar" mode="aspectFill"></image>
        </view>
        <view class="user-details">
          <view class="nickname-row" @click="handleNicknameClick">
            <text class="nickname">{{ isLoggedIn ? userInfo.nickname : '请登录' }}</text>
          </view>
          
          <!-- 认证标签和信用等级 -->
          <view class="tag-credit-row">
            <!-- 认证状态标签 -->
            <view class="verified-tag" v-if="isMerchantVerified()">
              <image class="verified-icon" :src="getImageUrl('/static/Images/user/Yirenzheng.png')" mode="aspectFit"></image>
            </view>
            <view class="unverified-tag" v-else>
              <image class="verified-icon" :src="getImageUrl('/static/Images/user/Weirenzheng.png')" mode="aspectFit"></image>
            </view>
            <view class="credit-level" :style="{ backgroundImage: `url(${backgroundImages.creditLevel})` }">
              <text class="level-text">信誉</text>
              <view class="stars">
                <image 
                  v-for="(icon, index) in getLevelIcons(userInfo.score)" 
                  :key="index"
                  class="level-star" 
                  :src="icon.src" 
                  mode="aspectFit"
                ></image>
              </view>
            </view>
          </view>
        </view>
      </view>
      <!-- 余额区域 -->
      <view class="balance-container" :style="{ backgroundImage: `url(${backgroundImages.wallet})` }">
        <view class="balance-item">
          <view class="balance-label">
            <text>我的余额(元)</text>
            <image class="eye-icon" :src="showBalance ? getImageUrl('/static/Images/user/Chakan.png') : getImageUrl('/static/Images/user/Yincang.png')" mode="aspectFit" @click="toggleBalanceVisibility"></image>
          </view>
          <text class="balance-value"  @click="navigateToBalance">{{ showBalance ? formatBalance(userInfo.money) : '******' }}</text>
        </view>
        <view class="balance-divider"></view>
        <view class="balance-item">
          <view class="balance-label">我的佣金(元)</view>
          <text class="balance-value" @click="navigateToCommission">{{ showBalance ? formatBalance(userInfo.balance) : '******' }}</text>
        </view>
      </view>
    </view>
    <!-- 新增的分割容器 -->
    <view class="split-container">
      <view class="split-item split-left">
        <text class="split-text"></text>
      </view>
      <view class="split-item split-right">
        <text class="split-text"></text>
      </view>
    </view>
    <!-- 订单和功能区域外层容器 -->
    <view class="content-outer-container">
      <!-- 我买的订单 -->
      <view class="order-section">
        <view class="section-header">
          <text class="section-title">我买的</text>
          <view class="view-all" @click="navigateToAllOrders('buy')">
            <text class="view-all-text">全部</text>
            <image class="arrow-icon" :src="getImageUrl('/static/Images/user/Quanbu.png')" mode="aspectFit"></image>
          </view>
        </view>
        
        <view class="order-icons">
          <view class="order-icon-item" @click="navigateToOrderList('buy', 'pending_payment')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Daifukuan.png')" mode="aspectFit"></image>
            <text class="order-icon-text">待付款</text>
          </view>
          <view class="order-icon-item" @click="navigateToOrderList('buy', 'pending_delivery')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Daifahuo.png')" mode="aspectFit"></image>
            <text class="order-icon-text">待发货</text>
          </view>
          <view class="order-icon-item" @click="navigateToOrderList('buy', 'pending_receipt')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Daishouhuo.png')" mode="aspectFit"></image>
            <text class="order-icon-text">待收货</text>
          </view>
          <view class="order-icon-item" @click="navigateToOrderList('buy', 'completed')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Jiaoyicheng.png')" mode="aspectFit"></image>
            <text class="order-icon-text">交易成功</text>
          </view>
          <view class="order-icon-item" @click="navigateToOrderList('buy', 'refund')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Tuikuan.png')" mode="aspectFit"></image>
            <text class="order-icon-text">退款/售后</text>
          </view>
        </view>
      </view>
      
      <!-- 我卖的订单 -->
      <view class="order-section">
        <view class="section-header">
          <text class="section-title">我卖的</text>
          <view class="view-all" @click="navigateToSellOrders">
            <text class="view-all-text">全部</text>
            <image class="arrow-icon" :src="getImageUrl('/static/Images/user/Quanbu.png')" mode="aspectFit"></image>
          </view>
        </view>
        
        <view class="order-icons">
          <view class="order-icon-item" @click="navigateToOrderList('sell', 'card_management')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Kamiguanli.png')" mode="aspectFit"></image>
            <text class="order-icon-text">卡密管理</text>
          </view>
          <view class="order-icon-item" @click="navigateToOrderList('sell', 'pending_delivery')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Daifahuo.png')" mode="aspectFit"></image>
            <text class="order-icon-text">待发货</text>
          </view>
          <view class="order-icon-item" @click="navigateToOrderList('sell', 'delivered')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Daishouhuo.png')" mode="aspectFit"></image>
            <text class="order-icon-text">已发货</text>
          </view>
          <view class="order-icon-item" @click="navigateToOrderList('sell', 'completed')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Jiaoyicheng.png')" mode="aspectFit"></image>
            <text class="order-icon-text">交易成功</text>
          </view>
          <view class="order-icon-item" @click="navigateToOrderList('sell', 'refund')">
            <image class="order-icon" :src="getImageUrl('/static/Images/user/Tuikuan.png')" mode="aspectFit"></image>
            <text class="order-icon-text">退款/售后</text>
          </view>
        </view>
      </view>
      
      <!-- 功能模块区域 -->
      <view class="feature-grid">
        <view class="feature-item" @click="navigateToFeature('distribution')">
          <image class="feature-icon" :src="getImageUrl('/static/Images/user/Fenxiao.png')" mode="aspectFit"></image>
          <text class="feature-text">分销管理</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('team')">
          <image class="feature-icon" :src="getImageUrl('/static/Images/user/Team.png')" mode="aspectFit"></image>
          <text class="feature-text">我的团队</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('verification')">
          <image class="feature-icon" :src="getImageUrl('/static/Images/user/Shiming.png')" mode="aspectFit"></image>
          <text class="feature-text">实名认证</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('customer_service')">
          <image class="feature-icon" :src="getImageUrl('/static/Images/user/Kefu.png')" mode="aspectFit"></image>
          <text class="feature-text">在线客服</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('registration_agreement')">
          <image class="feature-icon" :src="getImageUrl('/static/Images/user/Zhuce.png')" mode="aspectFit"></image>
          <text class="feature-text">注册协议</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('privacy_agreement')">
          <image class="feature-icon" :src="getImageUrl('/static/Images/user/Yinsi.png')" mode="aspectFit"></image>
          <text class="feature-text">隐私协议</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('business_cooperation')">
          <image class="feature-icon" :src="getImageUrl('/static/Images/user/Yewu.png')" mode="aspectFit"></image>
          <text class="feature-text">业务合作</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('platform_rules')">
          <image class="feature-icon" :src="getImageUrl('/static/Images/user/Guize.png')" mode="aspectFit"></image>
          <text class="feature-text">平台规则</text>
        </view>
      </view>
      
      <!-- 注释掉的重复功能模块
      <view class="feature-grid">
        <view class="feature-item" @click="navigateToFeature('registration_agreement')">
          <image class="feature-icon" src="/static/Images/user/Zhuce.png" mode="aspectFit"></image>
          <text class="feature-text">注册协议</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('privacy_agreement')">
          <image class="feature-icon" src="/static/Images/user/Yinsi.png" mode="aspectFit"></image>
          <text class="feature-text">隐私协议</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('business_cooperation')">
          <image class="feature-icon" src="/static/Images/user/Yewu.png" mode="aspectFit"></image>
          <text class="feature-text">业务合作</text>
        </view>
        <view class="feature-item" @click="navigateToFeature('platform_rules')">
          <image class="feature-icon" src="/static/Images/user/Guize.png" mode="aspectFit"></image>
          <text class="feature-text">平台规则</text>
        </view>
      </view>
      -->
    </view>
    
    <!-- 底部安全区域 -->
    <view class="safe-area-bottom"></view>
    
    <!-- 底部导航栏 -->
      <tab-bar :active="4"></tab-bar>
    </view>
    

  </PageContainer>
</template>

<script setup>
import { ref, reactive, computed, getCurrentInstance } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import TabBar from '@/components/TabBar.vue';
import { userStorage } from '@/utils/storage';
import { userApi, goodsApi } from '@/utils/api';
import { getImageUrl } from '@/config/api';

// 用户信息
const userInfo = reactive({
  nickname: '用户',
  avatar: '/static/Images/touxiang/1.png',
  verified: false,
  creditLevel: 1,
  score: 0, // 新增积分字段，用于等级图标显示
  balance: 0,
  commission: 0,
  money: 0, // 补充初始余额，避免首次渲染 toFixed 报错
  uid: '',
  real_name: '', // 保存实名认证姓名，用于路由判断与卖家入口校验
  idcard: '' // 保存实名认证身份证号码，用于卖家入口校验
});

// 获取当前组件实例，用于访问全局属性
const instance = getCurrentInstance();

// 清理头像 URL（去除可能的反引号和首尾空白）
const normalizeUrl = (url) => {
  if (typeof url !== 'string') return '';
  // 去掉包裹的反引号和首尾空白
  return url.replace(/^\s*`|`\s*$/g, '').trim();
};

// 获取用户信息
const fetchUserInfo = async () => {
  try {
    if (!isLoggedIn.value) return;
    const response = await userApi.getUserInfo();
    
    // 检查响应状态码，如果code为0，说明token无效，需要清除本地token并提示登录
    if (response && (response.code === 0 || response.code === '0')) {
      console.log('用户token已失效，清除本地存储并跳转登录');
      
      // 统一登出，清除所有相关本地存储
      userStorage.logout();
      
      // 提示用户重新登录
      uni.showModal({
        title: '提示',
        content: '登录已过期，请重新登录',
        showCancel: false,
        success: () => {
          // 跳转到登录页面
          uni.navigateTo({
            url: '/pages/login/login'
          });
        }
      });
      return;
    }
    
    // 兼容不同返回结构
    const data = (response && (response.data?.data ?? response.data ?? response)) || {};

    // 昵称：兼容 nick_name / nickname / name
    userInfo.nickname = data.nickname || data.name || data.nick_name || '用户';
    // 头像：清理反引号与空格
    const avatarUrl = normalizeUrl(data.avatar);
    userInfo.avatar = avatarUrl || '/static/Images/touxiang/1.png';
    // 认证：兼容 is_verify / verified（无则默认 false）
    userInfo.verified = data?.is_verify === 1 || data?.verified === true || false;
    // 等级：兼容 credit_level / credit / vip_level，优先使用vip_level字段，默认为 1
    console.log('=== 用户等级字段调试信息 ===');
    console.log('完整的data对象:', data);
    console.log('credit_level字段:', data?.credit_level, 'type:', typeof data?.credit_level);
    console.log('credit字段:', data?.credit, 'type:', typeof data?.credit);
    console.log('vip_level字段:', data?.vip_level, 'type:', typeof data?.vip_level);
    const level = data?.vip_level ?? data?.credit_level ?? data?.credit ?? 1;
    console.log('最终选择的level值:', level, 'type:', typeof level);
    userInfo.creditLevel = Number(level) || 1;
    console.log('转换后的creditLevel:', userInfo.creditLevel, 'type:', typeof userInfo.creditLevel);
    console.log('=== 调试信息结束 ===');
    // 积分：获取 score 字段，用于新的等级图标显示
    userInfo.score = Number(data?.score) || 0;
    // 余额：兼容 balance / money
    const balance = data?.balance ?? 0;
    userInfo.balance = Number(balance) || 0;
    // 佣金：兼容 commission / unbalance
    const money = data?.money ?? 0;
    userInfo.money = Number(money) || 0;
    // UID：优先 id 或 uid
    userInfo.uid = String(data.id ?? data.uid ?? (userInfo.uid || ''));
    // 新增：保存后端返回的 real_name，用于实名认证跳转判断
    userInfo.real_name = data?.real_name || '';
    // 新增：保存后端返回的身份证号码，兼容多种命名（idcard/id_card/idCard）
    userInfo.idcard = data?.idcard || '';
  } catch (error) {
    console.error('获取用户信息失败:', error);
  }
};

// 页面加载时获取URL参数和用户信息
onLoad((options) => {
  // 如果URL中包含verified参数，则根据参数值设置认证状态
  if (options && options.verified !== undefined) {
    // 将字符串转换为布尔值
    userInfo.verified = options.verified === 'true';
    console.log('认证状态通过URL参数设置为:', userInfo.verified);
  }
  
  // 获取用户信息
  fetchUserInfo();
});

// 页面显示时（返回该页或切换到该页）再次尝试获取用户信息
onShow(() => {
  // 延迟获取数据，确保页面完全加载
  setTimeout(() => {
    if (isLoggedIn.value) {
      fetchUserInfo();
    }
  }, 100);
});

// 控制余额显示/隐藏
const showBalance = ref(false);

// 检查登录状态
const isLoggedIn = computed(() => {
  return userStorage.isLoggedIn();
});

// 检查是否为小程序环境
const isMiniProgram = computed(() => {
  // #ifdef MP-WEIXIN
  return true;
  // #endif
  // #ifndef MP-WEIXIN
  return false;
  // #endif
});

// 登录引导相关（已使用全局方法）

// 处理昵称点击事件
const handleNicknameClick = () => {
  if (isLoggedIn.value) {
    // 已登录，跳转到设置页面
    uni.navigateTo({
      url: '/pages/users/settings'
    });
  } else {
    // 未登录，跳转到登录页面
    uni.navigateTo({
      url: '/pages/login/login'
    });
  }
};



// 切换余额显示/隐藏状态
const toggleBalanceVisibility = () => {
  showBalance.value = !showBalance.value;
};

// 格式化余额显示
const formatBalance = (value) => {
  const num = Number(value);
  const safeNum = Number.isFinite(num) ? num : 0;
  return safeNum.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};

// 背景图片URL计算属性
const backgroundImages = computed(() => ({
  creditLevel: getImageUrl('/static/Images/user/Xinyu.png'),
  wallet: getImageUrl('/static/Images/user/Wallet.png'),
  quanbu: getImageUrl('/static/Images/user/Quanbu.png')
}));

// 导航到设置页面
const navigateToSettings = () => {
  uni.navigateTo({
    url: '/pages/users/settings'
  });
};

// 新增：跳转余额页并通过 eventChannel 传值（不显示在URL）
const navigateToBalance = () => {
  const balanceValue = Number(userInfo.money) || 0;
  console.log('准备跳转余额页面，余额值:', balanceValue);
  
  // 先保存到本地存储作为兜底
  uni.setStorage({ key: 'latest_balance', data: balanceValue });
  
  uni.navigateTo({
    url: '/pages/wallet/balance',
    success: (res) => {
      try {
        console.log('页面跳转成功，开始传递余额数据');
        // 通过事件通道隐式传值，避免出现在URL
        if (res.eventChannel && res.eventChannel.emit) {
          res.eventChannel.emit('initBalance', { balance: balanceValue });
         
        } else {
          
        }
      } catch (e) {
        console.error('传递余额数据失败:', e);
        // 兜底处理，必要时可使用本地存储做降级
        uni.setStorage({ key: 'latest_balance', data: balanceValue });
      }
    },
    fail: (err) => {
      console.error('页面跳转失败:', err);
    }
  });
};

// 新增：跳转佣金页面
const navigateToCommission = () => {
  const commissionValue = Number(userInfo.balance) || 0;
  console.log('准备跳转佣金页面，佣金值:', commissionValue);
  
  // 先保存到本地存储作为兜底
  uni.setStorage({ key: 'latest_commission', data: commissionValue });
  
  uni.navigateTo({
    url: '/pages/wallet/commission',
    success: (res) => {
      try {
        console.log('佣金页面跳转成功，开始传递佣金数据');
        // 通过事件通道隐式传值，避免出现在URL
        if (res.eventChannel && res.eventChannel.emit) {
          res.eventChannel.emit('initCommission', { commission: commissionValue });
          
        } else {
          
        }
      } catch (e) {
        console.error('传递佣金数据失败:', e);
        // 兜底处理，必要时可使用本地存储做降级
        uni.setStorage({ key: 'latest_commission', data: commissionValue });
      }
    },
    fail: (err) => {
      console.error('佣金页面跳转失败:', err);
    }
  });
};
// 卖家模块认证判断：real_name 与 idcard 同时非空才算通过
const isMerchantVerified = () => {
  const rn = String(userInfo.real_name || '').trim();
  const ic = String(userInfo.idcard || '').trim();
  return !!(rn && ic);
};
// 导航到所有订单页面
const navigateToAllOrders = async (type) => {
  // 卖家板块需要完成实名认证
  if (type === 'sell') {
    if (!isMerchantVerified()) {
      instance.appContext.config.globalProperties.$showVerificationGuide();
      return;
    }
  }
  
  // 跳转到订单列表页面，买家订单传递all参数
  uni.navigateTo({
    url: `/pages/shop/orderlist?type=all`
  });
};

// 导航到订单列表页面
const navigateToOrderList = async (type, status) => {
  // 卖家板块需要完成实名认证
  if (type === 'sell') {
    if (!isMerchantVerified()) {
      instance.appContext.config.globalProperties.$showVerificationGuide();
      return;
    }
    // 卡密管理跳转到专门的卡密管理页面
    if (status === 'card_management') {
      uni.navigateTo({
        url: '/pages/shop/cardmanage'
      });
      return;
    }
    // 卖家订单直接跳转，带上status参数
    uni.navigateTo({
      url: `/pages/order/orderlist?type=0&status=${status}`
    });
    return;
  }
  
  // 买家订单跳转到shop/orderlist，type参数为订单状态
  uni.navigateTo({
    url: `/pages/shop/orderlist?type=${status}&status=${status}`
  })
};

// 导航到卖家订单页面
const navigateToSellOrders = async () => {
  // 卖家板块需要完成实名认证
  if (!isMerchantVerified()) {
    instance.appContext.config.globalProperties.$showVerificationGuide();
    return;
  }
  
  // 跳转到卖家订单列表页面
  uni.navigateTo({
    url: '/pages/order/orderlist?type=0'
  });
};

// 导航到功能页面
const navigateToFeature = (feature) => {
  const routes = {
    distribution: '/pages/fenxiao/index',
    team: '/pages/team/index',
    verification: '/pages/realname/index',
    customer_service: '/pages/common/customer-service',
    registration_agreement: '/pages/notice/textdetail?type=registration',
    privacy_agreement: '/pages/notice/textdetail?type=privacy',
    business_cooperation: '/pages/notice/textdetail?type=business',
    platform_rules: '/pages/notice/textdetail?type=rules'
  };

  // 我的团队：登录校验，直接跳转（不再携带参数）
  if (feature === 'team') {
    if (!isLoggedIn.value) {
      uni.navigateTo({ url: '/pages/login/login' });
      return;
    }
    uni.navigateTo({ url: '/pages/team/index' });
    return;
  }

  // 实名认证：根据 userInfo.real_name 是否为空跳转不同页面
  if (feature === 'verification') {
    if (!isLoggedIn.value) {
      uni.navigateTo({ url: '/pages/login/login' });
      return;
    }
    const hasRealName = !!(userInfo.real_name && String(userInfo.real_name).trim());
    const target = hasRealName ? '/pages/realname/certified' : '/pages/realname/index';
    uni.navigateTo({ url: target });
    return;
  }
  
  if (routes[feature]) {
    uni.navigateTo({
      url: routes[feature]
    });
  }
};

// 根据积分计算图标显示
// 新规则：
// 0-10分: 1个XX.png
// 11-40分: 2个XX.png
// 41-90分: 3个XX.png
// 91-150分: 4个XX.png
// 151-250分: 5个XX.png
// 251-500分: 1个ZS.png
// 501-1000分: 2个ZS.png
// 1001-2000分: 3个ZS.png
// 2001-5000分: 4个ZS.png
// 5001-10000分: 5个ZS.png
// 10001-20000分: 1个HG.png
// 20001-50000分: 2个HG.png
// 50001-100000分: 3个HG.png
// 100001-200000分: 4个HG.png
// 200001-500000分: 5个HG.png
const getLevelIcons = (score) => {
  const icons = []
  const numScore = Number(score) || 0
  
  if (numScore < 0) return icons
  
  // 根据积分范围确定图标类型和数量
  if (numScore <= 10) {
    // 0-10分: 1个XX
    icons.push({ type: 'xx', src: getImageUrl('/static/Images/common/XX.png') })
  } else if (numScore <= 40) {
    // 11-40分: 2个XX
    for (let i = 0; i < 2; i++) {
      icons.push({ type: 'xx', src: getImageUrl('/static/Images/common/XX.png') })
    }
  } else if (numScore <= 90) {
    // 41-90分: 3个XX
    for (let i = 0; i < 3; i++) {
      icons.push({ type: 'xx', src: getImageUrl('/static/Images/common/XX.png') })
    }
  } else if (numScore <= 150) {
    // 91-150分: 4个XX
    for (let i = 0; i < 4; i++) {
      icons.push({ type: 'xx', src: getImageUrl('/static/Images/common/XX.png') })
    }
  } else if (numScore <= 250) {
    // 151-250分: 5个XX
    for (let i = 0; i < 5; i++) {
      icons.push({ type: 'xx', src: getImageUrl('/static/Images/common/XX.png') })
    }
  } else if (numScore <= 500) {
    // 251-500分: 1个ZS
    icons.push({ type: 'zs', src: getImageUrl('/static/Images/common/ZS.png') })
  } else if (numScore <= 1000) {
    // 501-1000分: 2个ZS
    for (let i = 0; i < 2; i++) {
      icons.push({ type: 'zs', src: getImageUrl('/static/Images/common/ZS.png') })
    }
  } else if (numScore <= 2000) {
    // 1001-2000分: 3个ZS
    for (let i = 0; i < 3; i++) {
      icons.push({ type: 'zs', src: getImageUrl('/static/Images/common/ZS.png') })
    }
  } else if (numScore <= 5000) {
    // 2001-5000分: 4个ZS
    for (let i = 0; i < 4; i++) {
      icons.push({ type: 'zs', src: getImageUrl('/static/Images/common/ZS.png') })
    }
  } else if (numScore <= 10000) {
    // 5001-10000分: 5个ZS
    for (let i = 0; i < 5; i++) {
      icons.push({ type: 'zs', src: getImageUrl('/static/Images/common/ZS.png') })
    }
  } else if (numScore <= 20000) {
    // 10001-20000分: 1个HG
    icons.push({ type: 'hg', src: getImageUrl('/static/Images/common/HG.png') })
  } else if (numScore <= 50000) {
    // 20001-50000分: 2个HG
    for (let i = 0; i < 2; i++) {
      icons.push({ type: 'hg', src: getImageUrl('/static/Images/common/HG.png') })
    }
  } else if (numScore <= 100000) {
    // 50001-100000分: 3个HG
    for (let i = 0; i < 3; i++) {
      icons.push({ type: 'hg', src: getImageUrl('/static/Images/common/HG.png') })
    }
  } else if (numScore <= 200000) {
    // 100001-200000分: 4个HG
    for (let i = 0; i < 4; i++) {
      icons.push({ type: 'hg', src: getImageUrl('/static/Images/common/HG.png') })
    }
  } else {
    // 200001分以上: 5个HG
    for (let i = 0; i < 5; i++) {
      icons.push({ type: 'hg', src: getImageUrl('/static/Images/common/HG.png') })
    }
  }
  
  return icons
}
</script>

<style lang="scss">
.user-profile {
  width: 752rpx;
  min-height: auto;
  padding-bottom: 120rpx;
  background-color:#EEEFF4;
  margin: 0 auto;
}

/* 顶部个人信息区域 */
.user-header {
  position: relative;
  height: 400rpx;
}

.header-bg-image {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
}

.header-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(to bottom, #FF5151, #FF8282);
  z-index: -1;
}

.settings-btn {
  position: absolute;
  top: 20rpx;
  right: 30rpx;
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-icon {
  width: 40rpx;
  height: 40rpx;
}

.user-info {
  display: flex;
  align-items: center;
  padding: 60rpx 30rpx 0;
}

.avatar-container {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  border: 4rpx solid #fff;
  overflow: hidden;
  margin-right: 20rpx;
}

.avatar {
  width: 100%;
  height: 100%;
}

.user-details {
  flex: 1;
}

.nickname-row {
  display: flex;
  align-items: center;
  margin-bottom: 10rpx;
}

.nickname {
  font-size: 36rpx;
  color: #fff;
  font-weight: 500;
}

.tag-credit-row {
  display: flex;
  align-items: center;
  margin-top: 10rpx;
}

.verified-tag {
  display: flex;
  align-items: center;
  border-radius: 30rpx;
}

.unverified-tag {
  display: flex;
  align-items: center;
  border-radius: 30rpx;
  padding: 4rpx 12rpx;
}

.verified-icon {
  width: 160rpx;
  height: 65rpx;
  margin-right: 6rpx;
}

.verified-text {
  font-size: 22rpx;
  color: #fff;
}

.unverified-text {
  font-size: 22rpx;
  color: #fff;
}

.credit-level {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  height: 65rpx;
  width: 45%;
  position: relative;
  gap: 8rpx;
  padding-left: 20rpx;
}

.level-text {
  font-size: 24rpx;
  color: #fff;
  flex-shrink: 0;
}

.stars {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  flex: 1;
}

.star-icon {
  width: 24rpx;
  height: 24rpx;
  margin-right: 6rpx;
}

.level-star {
  width: 24rpx;
  height: 24rpx;
  display: block;
  object-fit: contain;
}

.level-star:not(:last-child) {
  margin-right: 6rpx;
}

/* 余额区域 */
.balance-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30rpx;
  margin: 35rpx 30rpx 30rpx;
  background-color: #FF5151;
  background-size: 120%;
  background-position: right center;
  background-repeat: no-repeat;
  border-radius: 20rpx;
}

.balance-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.balance-label {
  font-size: 26rpx;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 10rpx;
  display: flex;
  align-items: center;
}

.balance-label {
  display: flex;
  align-items: center;
}

.eye-icon {
  width: 30rpx;
  height: 20rpx;
  margin-left: 10rpx;
}

.balance-value {
  font-size: 36rpx;
  color: #fff;
  font-weight: 500;
  transition: opacity 0.2s ease;
}

.balance-divider {
  width: 2rpx;
  height: 60rpx;
  background-color: rgba(255, 255, 255, 0.3);
  margin: 0 20rpx;
}

/* 新增分割容器样式 */
.split-container {
  display: flex;
  position: relative;
  z-index: 3;
  margin-top: -36rpx; /* 向上切入balance-container */
  
  .split-item {
    width: 50%;
    height: 60rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-bottom: none;
    color: #666;
    background: #f5f5f5;
  }
}

.split-left {
  border-right: none; /* 隐藏右边框 */
  border-top-left-radius: 25rpx;
  border-top-right-radius: 28rpx;
}

.split-right {
  border-left: none; /* 隐藏左边框 */
  border-top-left-radius: 28rpx;
  border-top-right-radius: 25rpx;
}


/* 内容外层容器 */
.content-outer-container {
  position: relative;
  padding: 20rpx;
  z-index: 1;
  background: #f5f5f5;
  box-shadow: 0 -4rpx 8rpx 0 rgba(0,0,0,0.04);
  border-radius: 1rem;
  margin-top: -1rem;
}

/* 订单区域 */
.order-section {
  background-color: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  margin-top: 1rem;
  margin-left: 0.3rem;
  margin-right: 0.3rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30rpx;
}

.section-title {
  font-size: 32rpx;
  color: #333;
  font-weight: 500;
}

.view-all {
  display: flex;
  align-items: center;
}

.view-all-text {
  font-size: 26rpx;
  color: #999;
}

.arrow-icon {
  width: 24rpx;
  height: 24rpx;
  margin-left: 6rpx;
}

.order-icons {
  display: flex;
  justify-content: space-between;
}

.order-icon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 20%;
}

.order-icon {
  width: 60rpx;
  height: 60rpx;
  margin-bottom: 10rpx;
}

.order-icon-text {
  font-size: 24rpx;
  color: #666;
}

/* 功能模块区域 */
.feature-grid {
  margin-top: 1rem;
  background-color: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-left: 0.3rem;
  margin-right: 0.3rem;
}

.feature-item {
  width: 25%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30rpx;
}

.feature-icon {
  width: 60rpx;
  height: 60rpx;
  margin-bottom: 10rpx;
}

.feature-text {
  font-size: 24rpx;
  color: #666;
}

.safe-area-bottom {
  height: 68rpx;
  height: env(safe-area-inset-bottom);
}
</style>
